﻿Imports CapaLogica.CL.Usuario

Public Class frmGraduarEstudiante

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        If (txtCedula.Text = Nothing) Then
            MsgBox("Debe ingresar la cédula del estudiante", MsgBoxStyle.Critical)
        Else

            DataGridEstudiante.DataSource = GestorUsuario.buscarEstudiante(txtCedula.Text)
        End If

    End Sub

    Private Sub btnGraduar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGraduar.Click
        Dim existe As Boolean
        If ((DataGridEstudiante.CurrentRow Is Nothing) OrElse (DataGridEstudiante.SelectedRows.Count = 0)) Then
            MsgBox("Debe de seleccionar un estudiante antes de graduarlo", MsgBoxStyle.Exclamation, "Error")
            Exit Sub
        Else
            existe = GestorUsuario.buscarEstudianteGraduado(txtCedula.Text)

            If (existe) Then
                MsgBox("El estudiante seleccionado ya se encontraba graduado", MsgBoxStyle.Exclamation, "Error")
                Exit Sub
            Else
                Dim mensaje As String
                mensaje = "¿Desea graduar al estudiante?"
                Dim button As DialogResult = MessageBox.Show(mensaje, "Usuario", MessageBoxButtons.YesNoCancel,
                                                             MessageBoxIcon.Warning)
                If button = DialogResult.Yes Then
                    Try
                        GestorUsuario.graduarEstudiante(DataGridEstudiante.CurrentRow.Cells(0).Value.ToString(), Convert.ToString(DataGridEstudiante.CurrentRow.Cells(1).Value.ToString()))
                        MsgBox("El estudiante se ha graduado con éxito")
                        refrescar()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try
                End If
            End If
            
        End If


    End Sub

    Private Sub tsbCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbCancelar.Click
        Me.Dispose()
    End Sub

    Public Sub refrescar()
        txtCedula.Text = ""
        DataGridEstudiante.DataSource = Nothing
    End Sub

    Private Sub btnLimpiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        refrescar()
    End Sub
End Class